﻿using CL.Business.BLL;
using CL.Enum.Common.Union;
using CL.Tools.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CL.Admin.admin.promotion
{
    public partial class User_review : UI.AdminPage
    {
        protected int totalCount;
        protected int page;
        protected int pageSize;
        protected string searchKey;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.pageSize = GetPageSize(10); //每页数量
                RptBind(" CASE WHEN AccountStatus=4 THEN 0 ELSE 1 END, CreateTime DESC ");
            }
        }


        #region 数据绑定=================================
        private void RptBind(string _orderby)
        {
            this.page = QPRequest.GetQueryInt("page", 1);
            searchKey = QPRequest.GetQueryString("searchkey");
            AccountBLL bll = new AccountBLL();
            this.rptList.DataSource = bll.QueryListByPage(_orderby, this.page, this.pageSize, searchKey, ref this.totalCount);
            this.rptList.DataBind();
            //绑定页码
            txtPageNum.Text = this.pageSize.ToString();
            string pageUrl = Utils.CombUrlTxt("User_review.aspx", "page={0}&searchkey={1}", "__id__", searchKey);
            PageContent.InnerHtml = Utils.OutPageList(this.pageSize, this.page, this.totalCount, pageUrl, 8);
        }
        #endregion

        protected string GetTextColor(int accountStatus)
        {
            string css = "style=\"color: {0}\"";
            if ((int)AccountStatusEnum.noPass == accountStatus)
                css = string.Format(css, "blue");
            else if ((int)AccountStatusEnum.certification == accountStatus)
                css = string.Format(css, "red");
            else if ((int)AccountStatusEnum.normal == accountStatus)
                css = string.Format(css, "green");
            else
                css = "";
            return css;
        }

        protected string GetTextDesc(int accountStatus)
        {
            if ((int)AccountStatusEnum.disable == accountStatus)
                return "禁用";
            else if ((int)AccountStatusEnum.certification == accountStatus)
                return "待验证";
            else if ((int)AccountStatusEnum.noPass == accountStatus)
                return "未通过";
            else if ((int)AccountStatusEnum.normal == accountStatus)
                return "通过";
            else if ((int)AccountStatusEnum.toBeAudited == accountStatus)
                return "待上传";
            else
                return "未知状态";
        }


        #region 返回每页数量=============================
        private int GetPageSize(int _default_size)
        {
            int _pagesize;
            if (int.TryParse(Utils.GetCookie("User_review_page_size", "QPcmsPage"), out _pagesize))
            {
                if (_pagesize > 0)
                {
                    return _pagesize;
                }
            }
            return _default_size;
        }
        #endregion

        protected void txtPageNum_TextChanged(object sender, EventArgs e)
        {
            int _pagesize;
            if (int.TryParse(txtPageNum.Text.Trim(), out _pagesize))
            {
                if (_pagesize > 0)
                {
                    Utils.WriteCookie("User_review_page_size", "QPcmsPage", _pagesize.ToString(), 14400);
                }
            }
            Response.Redirect("User_review.aspx");
        }
    }
}